<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>函数只能执行 一次</title>
</head>
<body>
<script>
  function f() {
    console.log("call function f（）");
  }
/*
  // 是否可以执行
  let status = true
  function execute_once() {
    if (status){
      f()
      status = !status
    }
  }

  execute_once()
  execute_once()
  execute_once()
  execute_once()*/

  function execute_once(fn) {
    let status = true;
    return function () {
      if (status) {
        fn.apply(this.arguments)
        status = !status
      }
    }
  }


  let once = execute_once(f);
  once()
  once()
  once()

</script>
</body>
</html>